home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / CELARRAY.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  203 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.5  $
  6. //
  7. // Definition of a bitmap Cel array class.
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_CELARRAY_H)
  10. #define OWL_CELARRAY_H
  11.  
  12. #if !defined(OWL_GDIOBJCT_H)
  13. # include <owl/gdiobjec.h>
  14. #endif
  15.  
  16. #if defined(BI_NAMESPACE)
  17. namespace OWL {
  18. #endif
  19.  
  20. // Generic definitions/compiler options (eg. alignment) preceeding the 
  21. // definition of classes
  22. #include <services/preclass.h>
  23.  
  24. //
  25. // class TCelArray
  26. // ~~~~~ ~~~~~~~~~
  27. class _OWLCLASS TCelArray {
  28.   public:
  29.     // Constructors
  30.     //
  31.     TCelArray(TBitmap* bmp, int numCels, TSize celSize = 0,
  32.               TPoint offset = 0, TAutoDelete = AutoDelete);
  33.     TCelArray(const TDib& dib, int numCels);
  34.     TCelArray(const TCelArray& src);
  35.     TCelArray(const TSize& size, uint flags, int init, int grow);
  36.  
  37.     virtual   ~TCelArray();
  38.  
  39.     TCelArray& operator =(const TCelArray&);
  40.     operator   TBitmap&();
  41.  
  42.     // 'Get' accessors
  43.     //
  44.     TPoint     Offset() const;
  45.     int        NumCels() const;
  46.     TSize      CelSize() const;
  47.     TPoint     CelOffset(int cel) const;
  48.     TRect      CelRect(int cel) const;
  49.     TRect      operator [](int cel) const;
  50.  
  51.     // 'Set' accessors
  52.     //
  53.     void       SetNumCels(int numCels);
  54.     void       SetCelSize(TSize size);
  55.     void       SetOffset(TPoint offs);
  56.     void       SetNGrowBy(int growBy);
  57.  
  58.     // Manipulating cel images
  59.     //
  60.     int        Add(const TBitmap& image);
  61.     int        Add(const TCelArray& src, int index);
  62.  
  63.     bool       Remove(int index = -1);
  64.     bool       RemoveAll();
  65.     bool       Replace(int index, const TBitmap& image);
  66.     TColor     GetBkColor() const;
  67.     TColor     SetBkColor(const TColor&);
  68.  
  69.     bool       BitBlt(int index, TDC& dc, int x, int y);
  70.     bool       BitBlt(int index, TDC&, int x, int y, int dx, int dy,
  71.                       const TColor& bgClr, const TColor& fgClr);
  72.  
  73.   protected_data:
  74.     TBitmap*    Bitmap;         // Main Cel bitmap
  75.     bool        ShouldDelete;   // Does this CelArray own the Bitmap?
  76.     TPoint      Offs;           // Offset within Bitmap of actual CelArray
  77.     int         NCels;          // Number of cels allocated in Bitmap
  78.     TSize       CSize;          // Size of one cel
  79.     int         NGrowBy;        // How much to grow the array by when full
  80.     TColor      BkColor;        // Background color used when image < cellsize
  81.     int         NCelsUsed;      // Numbers of cels currently in use
  82.  
  83.   private:
  84.     bool        MaybeResize(int need);
  85.     bool        Resize(int newCount);
  86. };
  87.  
  88. // Generic definitions/compiler options (eg. alignment) following the 
  89. // definition of classes
  90. #include <services/posclass.h>
  91.  
  92. #if defined(BI_NAMESPACE)
  93. } // namespace OWL
  94. #endif
  95.  
  96. //------------------------------------------------------------------------
  97. // Inline implementations
  98. //
  99.  
  100. //
  101. // Return the offset within the bitmap for the celarray.
  102. //
  103. inline TPoint TCelArray::Offset() const {
  104.   return Offs;
  105. }
  106.  
  107. //
  108. // Return the size of the celarray.
  109. //
  110. inline TSize TCelArray::CelSize() const {
  111.   return CSize;
  112. }
  113.  
  114. //
  115. // Return number of cels currently in this CelArray
  116. //
  117. inline int TCelArray::NumCels() const {
  118.   return NCelsUsed;
  119. }
  120.  
  121. //
  122. // Retrieve the 'cel'th image from the celarray.
  123. //
  124. inline TRect TCelArray::operator [](int cel) const {
  125.   return CelRect(cel);
  126. }
  127.  
  128. //
  129. // Set the number of cels within the celarary.
  130. //
  131. inline void TCelArray::SetNumCels(int numCels) {
  132.   NCels = numCels < 1 ? 1 : numCels;
  133. }
  134.  
  135. //
  136. // Set the size of each cel.
  137. // They are all assumed to be the same.
  138. //
  139. inline void TCelArray::SetCelSize(TSize size) {
  140.   CSize = size;
  141. }
  142.  
  143. //
  144. // Set the increment by which the bitmap is resized
  145. //
  146. inline void TCelArray::SetNGrowBy(int growBy) {
  147.   NGrowBy = growBy;
  148. }
  149.  
  150. //
  151. // Set the offset within a bitmap for the start of the celarray.
  152. //
  153. inline void TCelArray::SetOffset(TPoint offs) {
  154.   Offs = offs;
  155. }
  156.  
  157. //
  158. // Remove all the cels from the array.
  159. //
  160. inline bool TCelArray::RemoveAll() {
  161.   return Remove(-1);
  162. }
  163.  
  164. //
  165. // Return the image bitmap used by this CelArray
  166. //
  167. //inline TCelArray::operator const TBitmap&() const  {
  168. //  return *Bitmap;
  169. //}
  170.  
  171. //
  172. // Return the image bitmap used by this CelArray
  173. //
  174. inline TCelArray::operator TBitmap&() {
  175.   return *Bitmap;
  176. }
  177.  
  178. #if !defined(OWL_NATIVECTRL_NEVER)
  179. //
  180. //inline TCelArray::operator HIMAGELIST() const {
  181. //  return ;
  182. //}
  183. #endif
  184.  
  185. //
  186. // Get the current background color for this CelArray
  187. //
  188. inline TColor TCelArray::GetBkColor() const {
  189.   return BkColor;
  190. }
  191.  
  192. //
  193. // Set the current background color for this CelArray, returning the previous
  194. // color.
  195. //
  196. inline TColor TCelArray::SetBkColor(const TColor& color) {
  197.   TColor obkColor = BkColor;
  198.   BkColor = color;
  199.   return obkColor;
  200. }
  201.  
  202. #endif  // OWL_CELARRAY_H
  203.